package nl.fonfolio.view.project {
	import flash.display.*;
	import flash.text.TextField;

	import nl.fonfolio.model.Model;
	import nl.fonfolio.controller.Controller;

	import nl.fonfolio.core.FonfolioEvent;	
	import nl.fonfolio.view.Rating;
	import nl.fonfolio.core.Fonfolio;	

	/**
	 * @author Niels
	 */
	public class ProjectRating extends Sprite {
		private var model:Model;
		private var controller:Controller;
		
		public var fonfolio:Fonfolio;
		public var rating : Rating;
		
		public var rate_lbl:TextField;
		public var votes_txt:TextField;
		public var votes_lbl:TextField;
		
		public function ProjectRating(fonfolio:Fonfolio,model:Model,controller:Controller) {
			this.fonfolio = fonfolio;
			this.model = model;
			this.controller = controller;
			
			this.model.addEventListener(FonfolioEvent.CONTROL_TYPE, this.update);
		}

		private function update(event : FonfolioEvent) : void {
			switch (event.command){
				case "LOAD_PROJECT":
					var currentProject:Object = this.model.getProject();
					
					for (var i : Number = 0;i <= currentProject.length - 1;i++) {
						this.rate_lbl.text = "Rate this project";
						this.votes_txt.text = currentProject[i].countVotes;
						this.rating = new Rating(this.fonfolio, this.model, this.controller);
						addChild(this.rating);
						this.rating.x = this.width/2-this.rating.width/2;
						this.rating.y = this.height/2-this.rating.height/2;
						this.votes_lbl.text = "votes";
					}
					
				break;
			}
		}
	}
}
